<template>
  <el-container class="container-home" style="height: 100%">
    <!--头部区域-->
    <el-header >
      <div>
        <img src="" alt="">
        <span>dian</span>
      </div>
      <el-button type="info" @click="logout">tuic</el-button>
    </el-header>
    <!--页面主体区域区域-->
    <el-container class="el-container">
      <div class="toggle-button">折叠/展开</div>
      <!--侧边栏区域-->
      <el-aside width="400px">
        <el-col :span="12">
          <!-- active-text-color选中高亮颜色-->
          <!--router开启路由模式-->
          <el-menu
              background-color="#333744"
              text-color="#fff"
              active-text-color="#ffd04b"
              unique-opened
              router
              :default-active="activePath"
          >
            <!--一级菜单-->
            <el-submenu :index="item.id+''" v-for="item in menulist" :key="item.id">
              <!--一级菜单模板区域-->
              <template slot="title">
                <!--图标-->
                <i class="el-icon-location"></i>
                <!--文本-->
                <span>{{item.authName}}</span>
              </template>


              <!--二级菜单-->
              <el-menu-item
                  :index="'/'+subItem.path"
                  v-for="subItem in item.children"
                  :key="subItem.id"
                  @click="saveNavState('/'+subItem.path)"
              >
              <!--二级菜单模板区域-->
              <template slot="title">
                <!--图标-->
                <i class="el-icon-location"></i>
                <!--文本-->
                <span>{{subItem.authName}}</span>
              </template>
              </el-menu-item>
            </el-submenu>

          </el-menu>
        </el-col>

      </el-aside>
      <!--右侧主体区域-->
      <el-main >
        <!--路由占位符-->
        <div>
          <router-view></router-view>
        </div>

      </el-main>
    </el-container>
  </el-container>


</template>

<script>
export default {
  name: "Home",
  data(){
    return{
    //左侧菜单数据
    menulist:[],
      activePath:"",
      authName:""
    }
  },
  created() {
    this.getMenuList()
  },
  methods:{
    logout(){
      //点击退出清除缓存的token
      window.sessi
      onStorage.clear()
      //跳转到login
      this.$router.push("/login")
    },
    async getMenuList() {
      const{data: res} =await this.$http.get('menus')
      if (res.meta.status!==200) return this.$message.error(res.meta.msg)
      this.menulist=res.data
      console.log(res)
    },
    saveNavState(activePath){
      window.sessionStorage.setItem('activePath',activePath)
      this.activePath=activePath

    }
  }

}
</script>

<style  scoped>
.container-home{
  height:100%;
  padding: 0;
}

.el-aside{
  background-color: #333744;}
  .el-menu{
    border-right: none;
  }

.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #fff;
  font-size: 20px;
}

> div {
  display: flex;
  align-items: center;
}

span {
  margin-left: 15px;
}
.el-main{
  background-color: #eaedf1;
}
.toggle-button{
  background-color: aqua;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
}
</style>
